// pages/push/fenlei.js
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    fenlei:[
    ],
    fenLeiEr:[],
      type:0
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },
  onLoad:function(e){
      var type = e.type;
      var that = this;
      that.setData({
          type:type
      })
      this.getDataList();
      // var that = this;
      // console.log('123'+JSON.stringify(that.data.fenlei))

  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  },

  change:function(e){
    var that = this;
    var index = e.currentTarget.dataset.index;
    var er;
    that.data.fenlei.forEach(function(d){
      if(d.bid == index){
        d.isselect = 1;
        er = d.erji;
      }else{
        d.isselect = 0;
      }
    })
    this.setData({
      fenlei:that.data.fenlei,
      fenLeiEr:er
    })
  },
  queren:function(e){
    wx.setStorageSync('unuse_type',e.currentTarget.dataset.name);
    wx.navigateBack();
  },
    getDataList:function(e){
    var that = this;
    var type = '';
    //1闲置2图书
    if(1 == that.data.type){
        type = 'xianzhitype';
    }else if(2 == that.data.type){
        type = 'xiaoshuostype';
    }
        wx.request({
            url: app.data.server+'/index.php/Tongcheng/Book/getDocDicByType?type=' + type,
            success:function(d){
                // console.log('123'+JSON.stringify(d.data));
                d.data[0].isselect = 1;
                // console.log(d.data)
                that.setData({
                    fenlei:d.data
                })
                that.data.fenlei.forEach(function(d){
                    if(1==d.isselect){
                        that.setData({
                            fenLeiEr:d.erji
                        })
                    }
                })
            }
        })
    },
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  }
})